package com.ophiux.websocket.controller;

import com.ophiux.websocket.model.InMessage;
import com.ophiux.websocket.model.OutMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.stereotype.Controller;

import java.time.LocalDateTime;

/**
 * @desc: 通过注解发送
 * @author: hhl
 * @date：2023/6/20 16:34
 */
@Controller
@Slf4j
public class GameInfoV1Controller {

    //消息路由，别人发送的消息会到这里来
    @MessageMapping("/v1/chat")
    @SendTo("/topic/game_chat")//发送哪里去，这种方式存在问题，暂时没有查找问题
    public OutMessage gameInfo(InMessage message) {
        log.info("/v1/chat接收信息：{}", message);
        OutMessage outMessage = new OutMessage();
        BeanUtils.copyProperties(message, outMessage);
        outMessage.setTime(LocalDateTime.now());
        return outMessage;
    }
}